package com.zyp.servlet;

import com.zyp.tool.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;

@WebServlet(name = "StudentServlet", urlPatterns = "/student")
public class StudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取到前端传来的数据，获取到状态，为增删改查
        String strings = null;
        String add = request.getParameter("add");
        if (add != null) {
            strings = Tool.CharacterConversion(add);
            response.sendRedirect("http://localhost:8081/task_4module_1/add.jsp");
        }
        String inquire = request.getParameter("inquire");
        if (inquire != null) {
            strings = Tool.CharacterConversion(inquire);
            //设置初始值
            Cookie cookie=new Cookie("yeshu","0");
            response.addCookie(cookie);
            pagingQueryServlet pagingQueryServlet = new pagingQueryServlet();
            //调用后台，添加数据
            pagingQueryServlet.doPost(request,response);
        }
        String delete = request.getParameter("delete");
        if (delete != null) {
            strings = Tool.CharacterConversion(delete);
            response.sendRedirect("http://localhost:8081/task_4module_1/delete.jsp");
        }
        String update = request.getParameter("update");
        if (update != null) {
            strings = Tool.CharacterConversion(update);
            response.sendRedirect("http://localhost:8081/task_4module_1/update.jsp");
        }

        System.out.println(strings);

        //获取到男女选择的值
//        String sex = request.getParameter("sex");
//        strings = Tool.CharacterConversion(sex);
//        System.out.println(strings);


    }



    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
